package com.email.send.service.imp;

import com.email.send.model.SendEmailModel;
import com.email.send.param.BodyType;
import com.email.send.param.EmailType;
import com.email.send.service.EmailService;
import com.email.send.util.EmailUtil;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class EmailServiceImpl implements EmailService {

    @Async("taskExecutor")
    @Override
    public void sendEmail(String emailKey, SendEmailModel model) {
        try {
            //异步执行
            Thread.sleep(1000);
            String textModel = EmailUtil.convertTextModel(BodyType.getByCode(emailKey), "rentao", "fang,很高兴认识你");
            //发送文本邮件
//            EmailUtil.sendEmail01(model.getReceiver(), EmailType.getByCode(emailKey),textModel);
            // 发送复杂邮件:文本+图片+附件
            String body = "自定义图片：<img src='cid:mj.jpg'/>,网络图片：<img src='https://www.baidu.com/img/bdlogo.png'/>";
             EmailUtil.sendEmail02(model.getReceiver(),"文本+图片+附件",body);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
